package com.eunion.core;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * bootstrap table page.
 * 
 * 
 * @version 2015-8-22
 */
public class PageParams {

	private Logger logger = LoggerFactory.getLogger(getClass());

	private String order; // "desc"

	private String sort;

	private String search;

	private Integer pageNumber;// 当前页码

	private Integer pageSize;// 每页记录数

	private Map<String, Object> searchparams = new HashMap<String, Object>();

	public PageParams() {
	}

	public Object getKey(String key) {
		return searchparams.get(key);
	}

	/**
	 * 获取字符串类型的值.
	 */
	public String getKeyString(String key) {
		Object obj = searchparams.get(key);
		if (null == obj) {
			return null;
		}
		return obj.toString();
	}

	/**
	 * 获取字符串类型的值+:00.
	 */
	public String getKeyDate00String(String key) {
		Object obj = searchparams.get(key);
		if (null == obj) {
			return null;
		}
		return obj.toString() + ":00";
	}

	/**
	 * 获取字符串类型的值+:59.
	 */
	public String getKeyDate59String(String key) {
		Object obj = searchparams.get(key);
		if (null == obj) {
			return null;
		}
		return obj.toString() + ":59";
	}

	/**
	 * 获取整数类型的值.
	 */
	public Integer getKeyInt(String key) {
		Object obj = searchparams.get(key);
		if (null == obj) {
			return null;
		}
		try {
			return Integer.valueOf(obj.toString());
		} catch (Exception e) {
			logger.warn("转换字符串{}为整数失败,将返回null {} ", key, e);
			return null;
		}
	}

	/**
	 * 是否降序.
	 */
	public boolean isDesc() {
		if (null == order || order.equals("desc")) {
			return true;
		}
		return false;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public Map<String, Object> getSearchparams() {
		return searchparams;
	}

	public void setSearchparams(Map<String, Object> searchparams) {
		this.searchparams = searchparams;
	}

	public Integer getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(Integer pageNumber) {
		this.pageNumber = pageNumber;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

}
